package com.link2room.quintesson.controller.manager;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.quintesson.dto.param.manager.TaobaoXrateManagerParamDto;
import com.link2room.quintesson.dto.result.manager.TaobaoXrateDto;
import com.link2room.quintesson.facade.ITaobaoXrateFacadeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by VegetaKo on 2017/1/12.
 */
@RestController
@RequestMapping("/manager/TaobaoXrates")
public class TaobaoXrateManagerController {

    @Resource
    private ITaobaoXrateFacadeService taobaoXrateFacadeService;

    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto taobaoXrateList(
            @RequestParam(value = "lhotelCode" ,required = false) String lhotelCode,
            @RequestParam(value = "rmtype" ,required = false) String rmtype,
            @RequestParam(value = "rpCode" ,required = false) String rpCode,
            @RequestParam(value = "currentPage" ,required = false) Integer currentPage,
            @RequestParam(value = "pageSize" ,required = false) Integer pageSize
    ) throws Exception {
        TaobaoXrateManagerParamDto taobaoXrateManagerParamDto=new TaobaoXrateManagerParamDto();
        taobaoXrateManagerParamDto.setLhotelCode(lhotelCode);
        taobaoXrateManagerParamDto.setRmtype(rmtype);
        taobaoXrateManagerParamDto.setRpCode(rpCode);
        taobaoXrateManagerParamDto.setCurrentPage(currentPage);
        taobaoXrateManagerParamDto.setPageSize(pageSize);
        QueryResult<TaobaoXrateDto> taobaoXrateDtoQueryResult = taobaoXrateFacadeService.listTaobaoXrate(taobaoXrateManagerParamDto);
        BaseResultDto<TaobaoXrateDto> baseResultDto=new BaseResultDto<>();
        baseResultDto.setResultCode(0);
        baseResultDto.setQueryResult(taobaoXrateDtoQueryResult);
        return baseResultDto;
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public BaseResultDto taobaoXrate(
            @PathVariable Long id
    ) throws Exception {
        TaobaoXrateManagerParamDto taobaoXrateManagerParamDto=new TaobaoXrateManagerParamDto();
        taobaoXrateManagerParamDto.setId(id);
        TaobaoXrateDto taobaoXrateDto = taobaoXrateFacadeService.findTaobaoXrate(taobaoXrateManagerParamDto);
        BaseResultDto<TaobaoXrateDto> baseResultDto=new BaseResultDto<>();
        baseResultDto.setResultCode(0);
        baseResultDto.setResultInfo(taobaoXrateDto);
        return baseResultDto;
    }

    @RequestMapping(method= RequestMethod.PUT)
    public BaseResultDto updateTaobaoXrateList(
            @RequestBody TaobaoXrateManagerParamDto taobaoXrateManagerParamDto
    )throws Exception{
        List<TaobaoXrateDto> taobaoXrateDtoList = taobaoXrateFacadeService.saveOrUpdateTaobaoXrateList(taobaoXrateManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setListToQueryResult(taobaoXrateDtoList);
        return l2rRs;
    }

    @RequestMapping(value = "/TaobaoXrate",method= RequestMethod.PUT)
    public BaseResultDto updateTaobaoXrate(
            @RequestBody TaobaoXrateManagerParamDto taobaoXrateManagerParamDto
    )throws Exception{
        TaobaoXrateDto taobaoXrateDto=taobaoXrateFacadeService.saveOrUpdateTaobaoXrate(taobaoXrateManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(taobaoXrateDto);
        return l2rRs;
    }
}
